let user = {
  "ba": '11231',
  "a": "Y",
  "name": "小明",
  "age": 20.999,
  "ball": "123124"
}

function getEncrStr (obj) {
  let keys = Object.keys(obj).sort()
  let str = ''
  let len = keys.length
  for (let index = 0; index < len; index++) {
    let key = keys[index]
    let currStr = key + '=' + user[key]
    if (len === 1) {
      str = currStr
      return str
    }
    let jointStr = index > 0 ? '&' : ''
    currStr = jointStr + currStr
    str = str + currStr
  }
  return str
}
console.log(getEncrStr(user))